Set up the project and display the scene from the Kanzi Studio project

When you create a new Kanzi Studio project with C application, Kanzi Studio creates a project with a Microsoft Visual Studio solution and adds template source code.

Kanzi creates a Kanzi Studio project in <KanziWorkspace>/Projects/<ProjectName>/Tool_project directory and the structure for the Visual Studio solution for your project in <KanziWorkspace>/Projects/<ProjectName>/Application:

Assets for the tutorial

The starting point of this tutorial is stored in <KanziWorkspace>/Tutorials/Adding code/Start here:

You can find the completed tutorial in <KanziWorkspace>/Examples/Programmer_tutorial.

Set up the project and display the scene from the Kanzi Studio project

  1. In Kanzi Studio open the Programmer_tutorial project and select File > Export KZB Binary.
    Kanzi Studio creates the binary and configuration files from your Kanzi Studio project and stores them in <KanziWorkspace>/Projects/<ProjectName>/Application/bin. When you run your Kanzi application from Visual Studio, your Visual Studio solution reads these files to create your Kanzi application.
  2. In Visual Studio open the solution stored in <KanziWorkspace>/Tutorials/Adding code/Start here/Programmer_tutorial/Application/configs/platforms/win32/Programmer_tutorial.sln, set Programmer_tutorial_executable as your startup project, and open programmer_tutorial.c.
    programmer_tutorial.c contains the minimum amount of code required for loading a Kanzi application. The important function is the kzApplicationConfigure entry point:
    #include <application/kza_application_interface.h>
    #include <application/kza_application.h>
    
    KZ_CALLBACK static kzsError keyInputEventHandler (struct KzaApplication* application,
    	const struct KzsInputEventKey* inputData)
    {
    	enum KzsInputKey button = kzsInputEventKeyGetButton(inputData);
    
    	/* Handle the escape or Q button to exit the application. */
    	if (button == KZS_KEY_ESC || button == KZS_KEY_Q)
    	{
    		kzaApplicationQuit(application);
    	}
    
    	kzsSuccess();
    }
    					
    /* Application configuration function. Application framework calls this function */
    /* when the application is started, but before it is initialized. */
    KZ_CALLBACK void kzApplicationConfigure(const struct KzaSystemProperties* systemProperties,
    	struct KzaApplicationProperties* configuration)
    {
    	/* Defines the amount of memory reserved for your Kanzi application. */	
    	configuration->memoryPoolSize = 20 * 1024 * 1024;
    
    	/* Defines the name of the configuration file (in this case Programmer_tutorial.kzb.cfg") */
    	/* containing a list of names of the Kanzi Studio binary files (kzb) */
    	/* the application loads at startup (in this case only Programmer_tutorial.kzb). */
    	configuration->binaryName = "Programmer_tutorial.kzb.cfg";
    
    	/* Defines the callback functions by setting them in the KzaApplicationProperties */
    	/* instance passed by Kanzi as a parameter. */
    	/* In this case only the handler for key input events is implemented. Later in the tutorial */
    	/* you add implementations for other callbacks. */
    	configuration->onKeyInputEvent = keyInputEventHandler;
    }
  3. In kzApplicationConfigure define
    /* A callback function for initialization after loading the kzb binary. */
    KZ_CALLBACK static kzsError projectLoaded(struct KzaApplication* application)
    {
    	kzsSuccess();
    }
    
    /* A callback function for deinitialization when shutting down the application. */
    KZ_CALLBACK static kzsError shutdown(struct KzaApplication* application)
    {
    	kzsSuccess();
    }
    			
    KZ_CALLBACK void kzApplicationConfigure(const struct KzaSystemProperties* systemProperties,
    struct KzaApplicationProperties* configuration)
    {
    	...
    
    /* Platform dependent configuration options such as window size and anti-aliasing. */
    /* For example, on Windows and Linux, the application runs in a default */
    /* application 800 by 480 pixels window with anti-aliasing on. When you run */
    /* this application another platform, anti-aliasing is off and the platform sets */
    /* the size of the window. Most mobile devices show the application in full-screen. */
    #if defined WIN32 || defined __linux__
    	configuration->windowProperties.style = KZS_WINDOW_STYLE_DEFAULT;
    	configuration->windowProperties.width = 800;
    	configuration->windowProperties.height = 480;
    #endif
    
    	/* Function callback for later initialization. */
    	/* Kanzi calls this function after it loads the kzb binaries. */
    	configuration->onProjectLoaded = projectLoaded;
        
    	/* Function callback for deinitialization. */
    	/* Kanzi calls this function when during application shutdown, but */
    	/* before it releases anything. */
    	configuration->onShutdown = shutdown;
    }
  4. In Visual Studio select one of the available debug solution configurations and run your application.
    For example, select ES2_IMG_Debug solution configuration.

    When you build and run the program, this is what it looks like

    During an application launch Kanzi:
    1. Calls the kzApplicationConfigure entry point function, where the configuration you specify is determined.
    2. Loads the Kanzi Studio project binary file to memory, which makes it available for the rest of the application framework.
    3. When it completes loading of the project, it calls the callback function defined in KzaApplicationProperties.onProjectLoaded. You implement your program here.

< PREVIOUS STEP

NEXT STEP >